package com.tledu.stu_manager.service;

import com.tledu.stu_manager.dao.RoleDao;
import com.tledu.stu_manager.exception.CustomException;
import com.tledu.stu_manager.model.Role;

import java.util.List;

/**
 * 角色service
 *
 * @author Antg
 * @date 2021/8/120:57
 */
public class RoleService {
    private final RoleDao roleDao;

    public RoleService(RoleDao roleDao) {
        this.roleDao = roleDao;
    }

    /**
     * 查询所有
     *
     * @author Antg
     * @date 2021/8/1 20:57
     */
    public List<Role> findAll() throws CustomException {
        return roleDao.findAll();
    }

    /**
     * 根据角色名称模糊查询
     *
     * @author Antg
     * @date 2021/8/1 20:57
     */
    public List<Role> findByRoleName(String roleName) throws CustomException {
        return roleDao.findByRoleName(roleName);
    }

    /**
     * 通过id查询
     *
     * @author Antg
     * @date 2021/8/2 9:53
     */

    public Role findById(Integer id) throws CustomException {
        return roleDao.findById(id);
    }

    /**
     * 添加
     *
     * @author Antg
     * @date 2021/8/1 20:57
     */
    public void addRole(Role role) throws CustomException {
        roleDao.addRole(role);
    }

    /**
     * 编辑
     *
     * @author Antg
     * @date 2021/8/1 20:58
     */
    public void editRole(Role role) throws CustomException {
        roleDao.editRole(role);
    }

    /**
     * 删除
     *
     * @author Antg
     * @date 2021/8/1 20:58
     */
    public void delRole(Integer id) throws CustomException {
        roleDao.delRole(id);
    }

    /**
     * 批量删除
     *
     * @author Antg
     * @date 2021/8/1 20:58
     */
    public void batchDelRole(String idList) throws CustomException {
        String[] tempList = idList.split(",");
        Integer[] list = new Integer[tempList.length];
        for (int i = 0; i < tempList.length; i++) {
            list[i] = Integer.parseInt(tempList[i]);
        }

        roleDao.batchDelRole(list);
    }
}
